Skip to content

SOLR-18125 Make LukeRequestHandler::getFirstLiveDoc get the first live doc#4157

Merged
dsmiley merged 4 commits intoapache:mainfrom
kotman12:fix-getFirstLiveDoc
Mar 21, 2026
Merged

SOLR-18125 Make LukeRequestHandler::getFirstLiveDoc get the first live doc#4157
dsmiley merged 4 commits intoapache:mainfrom
kotman12:fix-getFirstLiveDoc

Conversation

@kotman12
Copy link
Copy Markdown
Contributor

@kotman12 kotman12 commented Feb 22, 2026

Description

LukeRequestHandler::getFirstLiveDoc is completely broken.

Funny little expedition as I was testing a patch I had to support distrib=true for LukeRequestHandler. It turns out the logic to fetch the first live doc from the index for a particular field (used to populate the index flags for that field) is broken in two surprising ways. As far as I can tell it's been broken since 2012. The net effect is you'll just randomly not get index flags for fields as I show in the test.

Timeline:

  • LUCENE-4355 Before this change docsEnum = reader.termDocsEnum(liveDocs, field, termText, offset) apparently would return null, perhaps when there were no live docs for this particular term. There used to be a guard in the loop condition which ensured that it would exit on the first non-null docsEnum it encountered across all terms. Not entirely sure why exactly this extra condition was necessary; it would only matter if the first non-null docsEnum also didn't have any docs. Either away, reaching such a state apparently warranted ending the search altogether. LUCENE-4355 changed the semantics to termsEnum.docs(liveDocs, docsEnum, offset) which could not return null, as much is obvious from the fact that the inner null check disappeared. However, the earlier docsEnum == null remained in the loop condition, almost certainly by mistake.
  • LUCENE-6553 this massive change seemed to introduce the exact opposite liveDocs check you'd expect from this method (somehow exiting the loop with no result when a live doc was encountered). I suspect it is, again, an oversight given how large the change was and how little discussion there was around it.

Solution

Fix the bug and git rid of a vestigial check. Diffs of how we got here mentioned in JIRA.

Tests

Quite easily show that you get no index flags when you should get index flags.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

@github-actions github-actions bot added the tests label Feb 22, 2026
@sigram
Copy link
Copy Markdown
Contributor

sigram commented Feb 25, 2026

Well spotted! Patch looks good to me.

@kotman12 kotman12 mentioned this pull request Feb 26, 2026
8 tasks
@dsmiley
Copy link
Copy Markdown
Contributor

dsmiley commented Mar 6, 2026

Can you then please merge & backport this @sigram ?

@dsmiley
Copy link
Copy Markdown
Contributor

dsmiley commented Mar 18, 2026

Can you add a changelog please?

getFieldXPathPrefix("solr_s") + "[@name='index']");
} finally {
deleteCore();
System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that our test infra clears all props that were set at the end of each test, thus this line here isn't necessary. No big deal.

@kotman12
Copy link
Copy Markdown
Contributor Author

Can you add a changelog please?

Sure, I thought this fix was so small it didn't warrant a changelog entry but I'll ad one.

@dsmiley dsmiley merged commit 57200fc into apache:main Mar 21, 2026
5 checks passed
dsmiley pushed a commit that referenced this pull request Mar 28, 2026
…e doc (#4157)

Fix getFirstLiveDoc so it returns the first live doc. Previously it would often return nothing resulting in missing index flags in /admin/luke response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants